package day1;

/**
 * @author oldliu
 * @since 1.0
 */
public class SystemTest {
    public static void main(String[] args) {
        //System.exit(1);
        //1970-1-1 到现在的毫秒数
        long time = System.currentTimeMillis();
        System.out.println(time);
        //执行花费的时间
        int a=100,b=41;
        int c=a*b;
        System.out.println(c);
        long time2=System.currentTimeMillis();
        System.out.println("这个乘法耗时："+(time2-time)+"毫秒");
        //nanoTime:纳秒,计算时间差
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        long begin1=System.nanoTime();
        long fb = fb(40);
        System.out.println(fb);
        long end1=System.nanoTime();
        System.out.println("递归的方式耗时："+(end1-begin1)+"纳秒");
        long begin2=System.nanoTime();
        long fb2 = fb2(40);
        System.out.println(fb2);
        long end2=System.nanoTime();
        System.out.println("for的方式耗时："+(end2-begin2)+"纳秒");
        try{
            System.out.println("你好，System");
            System.exit(0);
        }finally {
            System.out.println("程序结束了");
        }
    }
    //递归实现
    public static long fb(int k){
        if(k<=2)
            return 1;
        return fb(k-1)+fb(k-2);
    }
    //for实现
    public static long fb2(int k){
        if(k<=2)
            return 1;
        int first=1,second=1;
        int three=0;
        for(int i=3;i<=k;i++){
            three=first+second;
            first=second;
            second=three;
        }
        return three;
    }

}
